package j04duotai;

public class J1 {
}

class Animal{}
class Dog extends Animal{
    public void lookDoor(){
        System.out.println("看门");
    }
}
class Cat extends Animal{
    public void catchMouse(){
        System.out.println("抓老鼠");
    }
}

class AnimalTest{
    public static void main(String[] args) {
        //instanceof检测对象属于哪个类
        Dog x = new Dog();
        System.out.println(x instanceof Dog);//true
//        System.out.println(x instanceof Cat);//false

        Animal a1 = x;//a1的真身时Dog
        System.out.println(a1 instanceof Dog);//true
        System.out.println(a1 instanceof Cat);//false
        System.out.println("========");
        //多态会失去自己的新特性
        Animal a11 = new Dog();
//        a11.lookDoor();
        //强转，可以获取失去的新特性，强转的真身，必须时他本来的类型
//        Dog d11 = (Dog)a11;
//        d11.lookDoor();

//        Cat c11 = (Cat)a11;
//        c11.catchMouse();

        if(a11 instanceof Dog){
            //dog
        }else{
            //cat
        }
    }
}